package com.example.viewmodelstudio.databinding2;

import android.util.Log;

import androidx.databinding.BaseObservable;
import androidx.databinding.Bindable;

import com.example.viewmodelstudio.BR;

public class UserViewModel extends BaseObservable {
    private User user;

    public UserViewModel() {
        this.user = new User("九尾妖狐");
    }

    /**
     * 加上注解 @Bindable 只要数据发生变化就会通知UI
     */
    @Bindable
    public String getUserName() {
        return user.userName;
    }

    public void setUserName(String userName) {
        if (userName != null && !userName.equals(user.userName)) {
            this.user.userName = userName;
            Log.d("zdl", "======================" + userName);
            notifyPropertyChanged(BR.userName);
        }
    }
}
